package com.lyc.domain.activity.service.quota.rule.factory;

import com.lyc.domain.activity.service.quota.rule.IActionChain;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @author lyc
 * @description 责任链工厂
 */
@Service
public class DefaultActivityChainFactory {

    private final IActionChain actionChain;

    /**
     * <p>1. 通过构造函数注入。</p>
     * <P>2. Spring 可以自动注入 IActionChain 接口实现类到 map 对象中，key 就是 bean 的名字。</P>
     * <P>3. 活动下单动作的责任链是固定的【基础链(校验活动的日期，状态，剩余库存）->库存扣减处理链】，所以直接在构造函数中组装即可。</P>
     */
    public DefaultActivityChainFactory(Map<String, IActionChain> actionChainGroup) {
        actionChain = actionChainGroup.get(ActionModel.activity_base_action.code);
        actionChain.appendNext(actionChainGroup.get(ActionModel.activity_sku_stock_action.getCode()));
    }

    public IActionChain openActionChain() {
        return this.actionChain;
    }

    @Getter
    @AllArgsConstructor
    public enum ActionModel {

        activity_base_action("activity_base_action", "活动的库存、时间、状态校验"),
        activity_sku_stock_action("activity_sku_stock_action", "活动sku库存扣减"),
        ;

        private final String code;
        private final String info;

    }

}
